<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php include('functions.php'); ?>

<?php 

if ((isset($_GET['categoryid'])) && ($_GET['categoryid'] != "")) {

	$deleteGoTo = "category_list.php";

	$colname_productsbycategory = "-1";
	if (isset($_GET['categoryid'])) {
	  $colname_productsbycategory = (get_magic_quotes_gpc()) ? $_GET['categoryid'] : addslashes($_GET['categoryid']);
	}
	mysql_select_db($database_locamedicadmin, $locamedicadmin);
	$query_productsbycategory = sprintf("SELECT product_id FROM csre_product WHERE category_id = %s", $colname_productsbycategory);
	$productsbycategory = mysql_query($query_productsbycategory, $locamedicadmin) or die(mysql_error());
	$row_productsbycategory = mysql_fetch_assoc($productsbycategory);
	$totalRows_productsbycategory = mysql_num_rows($productsbycategory);  
  
  if ($totalRows_productsbycategory > 0) {
  	header(sprintf("Location: %s?categoryused=categoryused", $deleteGoTo));
  } else {
  
  $deleteSQL = sprintf("DELETE FROM csre_category WHERE category_id=%s",
                       GetSQLValueString($_GET['categoryid'], "int"));

  mysql_select_db($database_locamedicadmin, $locamedicadmin);
  $Result1 = mysql_query($deleteSQL, $locamedicadmin) or die(mysql_error());

  
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
  
  }
  mysql_free_result($productsbycategory);
}


?>